<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
 <!DOCTYPE html>
<html>

<head>
	<base href="/">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    

    <title>用户-域名列表</title>
    <meta name="keywords" content="用户-域名列表">
    <meta name="description" content="用户-域名列表">

    <link rel="shortcut icon" href="favicon.ico"> 
    <link href="static/templet/css/bootstrap.min.css?v=3.3.5" rel="stylesheet">
    <link href="static/templet/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
    <link href="static/templet/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="static/templet/css/animate.min.css" rel="stylesheet">
    <link href="static/templet/css/style.min862f.css?v=4.1.0" rel="stylesheet">

</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
    <form action="user" method="post" id="userForm">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-content">
                    	<c:if test="${proxy }">
                    	<a class="btn btn-primary " href="javascript:add();" target="_self">绑定外部域名</a>
                    	</c:if>
                        <table class="table table-hover">
                            <thead>
                                <tr>
                                    <th>域名</th>
                                    <th>状态</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                            <c:if test="${!empty domain }">
                            <tr>
                            	<td>${domain }${empty port?"":(":".concat(port)) }</td>
                            	<td>启用</td>
                            	<td>系统赠送域名，不可操作</td>
                            </tr>
                            </c:if>
							<c:forEach items="${userDomainList}" var="ud" varStatus="vs">
                            	<tr>
                                    <td>${ud.domain}${empty port?"":(":".concat(port)) }</td>
									<td>
									<c:choose>
                                    	<c:when test="${ud.state eq '01' }">
                                    	启用
                                    	</c:when>
                                    	<c:otherwise>
                                    	关闭
                                    	</c:otherwise>
                                    </c:choose>
									</td>
                                    <td>
                                    <a href="javascript:del('${ud.id}');" title="取消绑定">取消绑定</a> 
                                    <c:choose>
                                    	<c:when test="${ud.state eq '01' }">
                                    	<a href="javascript:confirmState('${ud.id}','00');" title="关闭">关闭</a>
                                    	</c:when>
                                    	<c:otherwise>
                                    	<a href="javascript:confirmState('${ud.id}','01');" title="启用">启用</a>
                                    	</c:otherwise>
                                    </c:choose>
                                    
                                    </td>
                                </tr>
                            </c:forEach>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
        </form>
    </div>
    <script src="static/templet/js/jquery.min.js?v=2.1.4"></script>
    <script src="static/templet/js/bootstrap.min.js?v=3.3.5"></script>
    <script src="static/templet/js/plugins/peity/jquery.peity.min.js"></script>
    <script src="static/templet/js/plugins/layer/layer.min.js"></script>
    <script src="static/templet/js/iframe.min.js"></script>
    <script type="text/javascript">

    
    function add(){
    	layer.open({
    	    type: 2,
    	    title: '绑定外部域名',
    	    shadeClose: true,
    	    shade: 0.8,
    	    area: ['90%', '90%'],
    	    content: 'user/domain/add',
    	    cancel:function(index, layero){
    	    	iframe.get(layero);
    	    	if(result == 1){
    	    		location.reload(true);
    	    	}
    	    	
    	    }
    	});
    }

    function del(id){
    	layer.confirm('移除后该域名则无法访问', {
    	    btn: ['确定'], //按钮
    	    shade: false //不显示遮罩
    	}, function(){
    	$.post('user/domain/delete',{id:id}, function(data, status){
			if(status == 'success'){
				var result = data.result;
				var state = result.state;
				if(state == 1){
					layer.msg('移除成功', {icon: 1});
					location.reload();
				}else{
					layer.msg(result.message, {icon: 1});
				}
			}
		})
    	})
    }

    function confirmState(id, state){
		if(state == '00'){
			layer.confirm('禁用后该域名则无法访问', {
	    	    btn: ['确定'], //按钮
	    	    shade: false //不显示遮罩
	    	}, function(){
		    	updateState(id, state, '禁用成功');
	    	})
		}else{
			updateState(id, state, '启用成功');
		}
    	
    }

    function updateState(id, state, msg){
    	$.post('user/domain/updateState',{id:id,state:state}, function(data, status){
			if(status == 'success'){
				var result = data.result;
				var state = result.state;
				if(state == 1){
					layer.msg(msg, {icon: 1});
					location.reload();
				}else{
					layer.msg(result.message, {icon: 1});
				}
			}
		})
    	
    }
  
    </script>

</body>

</html>